Convert Gail(Sub)MenuItem to GtkAccessible classes
authorMatthias Clasen <mclasen@redhat.com>
Fri, 1 Jul 2011 20:59:46 +0000 (16:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:57 +0000 (16:08 -0400)
This is along the same lines as the previous commit,
with the same caveat.

17 files changed:
gtk/a11y/Makefile.am
gtk/a11y/gail.c
gtk/a11y/gailcontainer.h
gtk/a11y/gailmenuitem.c [deleted file]
gtk/a11y/gailmenuitem.h [deleted file]
gtk/a11y/gailsubmenuitem.c [deleted file]
gtk/a11y/gailsubmenuitem.h [deleted file]
gtk/a11y/gtkcheckmenuitemaccessible.c
gtk/a11y/gtkcheckmenuitemaccessible.h
gtk/a11y/gtkchecksubmenuitemaccessible.c
gtk/a11y/gtkchecksubmenuitemaccessible.h
gtk/a11y/gtkexpanderaccessible.c
gtk/a11y/gtkmenuitemaccessible.c [new file with mode: 0644]
gtk/a11y/gtkmenuitemaccessible.h [new file with mode: 0644]
gtk/a11y/gtksubmenuitemaccessible.c [new file with mode: 0644]
gtk/a11y/gtksubmenuitemaccessible.h [new file with mode: 0644]
gtk/gtkmenuitem.c

index f3103050b4a7fae60a32e8cfe820d188bfefbc40..922c077fcb010c7b635ab80a1d36bb1b5c545e0f 100644 (file)
@@ -25,7 +25,7 @@ gail_c_sources =                      \
        gailmisc.c                      \
        gailmenu.c                      \
        gailmenushell.c                 \
-       gailmenuitem.c                  \
+       gtkmenuitemaccessible.c         \
        gtknotebookaccessible.c         \
        gtknotebookpageaccessible.c     \
        gtkpanedaccessible.c            \
@@ -40,7 +40,7 @@ gail_c_sources =                      \
        gtkscrollbaraccessible.c        \
        gtkscrolledwindowaccessible.c   \
        gtkspinbuttonaccessible.c       \
-       gailsubmenuitem.c               \
+       gtksubmenuitemaccessible.c      \
        gtkstatusbaraccessible.c        \
        gailtextcell.c                  \
        gailtextutil.c                  \
@@ -77,7 +77,7 @@ gail_private_h_sources =              \
        gailmisc.h                      \
        gailmenu.h                      \
        gailmenushell.h                 \
-       gailmenuitem.h                  \
+       gtkmenuitemaccessible.h         \
        gtknotebookaccessible.h         \
        gtknotebookpageaccessible.h     \
        gtkpanedaccessible.h            \
@@ -92,7 +92,7 @@ gail_private_h_sources =              \
        gtkscrollbaraccessible.h        \
        gtkscrolledwindowaccessible.h   \
        gtkspinbuttonaccessible.h       \
-       gailsubmenuitem.h               \
+       gtksubmenuitemaccessible.h      \
        gtkstatusbaraccessible.h        \
        gailtextcell.h                  \
        gailtextutil.h                  \
index bcb867b6727780caadf811147ffd5d24830aa89d..cb8cfc4d8078f4e86e5969a236d98b915cafba18 100644 (file)
@@ -31,7 +31,6 @@
 #include "gailimagecell.h"
 #include "gailmenu.h"
 #include "gailmenushell.h"
-#include "gailmenuitem.h"
 #include "gailrenderercell.h"
 #include "gailtextcell.h"
 #include "gailtoplevel.h"
@@ -86,7 +85,6 @@ static GQuark quark_focus_object = 0;
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WIDGET, GailWidget, gail_widget, GTK_TYPE_WIDGET)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_CONTAINER, GailContainer, gail_container, GTK_TYPE_CONTAINER)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_BUTTON, GailButton, gail_button, GTK_TYPE_BUTTON)
-GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_MENU_ITEM, GailMenuItem, gail_menu_item, gail_menu_item_new)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU_SHELL, GailMenuShell, gail_menu_shell, GTK_TYPE_MENU_SHELL)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_MENU, GailMenu, gail_menu, GTK_TYPE_MENU)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WINDOW, GailWindow, gail_window, GTK_TYPE_BIN)
@@ -837,7 +835,6 @@ gail_accessibility_module_init (void)
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_WIDGET, gail_widget);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CONTAINER, gail_container);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_BUTTON, gail_button);
-  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_ITEM, gail_menu_item);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_BAR, gail_menu_shell);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU, gail_menu);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_WINDOW, gail_window);
index 01241996a2d34923af1999f5c556dd4983de1ed4..d5094f6e6465131d06b23b4354b3843784d32165 100644 (file)
@@ -38,10 +38,7 @@ struct _GailContainer
 {
   GailWidget parent;
 
-  /*
-   * Cached list of children
-   */
-  GList      *children;
+  GList *children;
 };
 
 GType gail_container_get_type (void);
diff --git a/gtk/a11y/gailmenuitem.c b/gtk/a11y/gailmenuitem.c
deleted file mode 100644 (file)
index cb81de6..0000000
+++ /dev/null
@@ -1,806 +0,0 @@
-/* GAIL - The GNOME Accessibility Implementation Library
- * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include <string.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-#include "gailmenuitem.h"
-#include "gailsubmenuitem.h"
-
-#define KEYBINDING_SEPARATOR ";"
-
-static void gail_menu_item_class_init  (GailMenuItemClass *klass);
-static void gail_menu_item_init        (GailMenuItem      *menu_item);
-
-static void                  gail_menu_item_real_initialize
-                                                          (AtkObject       *obj,
-                                                           gpointer        data);
-static gint                  gail_menu_item_get_n_children (AtkObject      *obj);
-static AtkObject*            gail_menu_item_ref_child      (AtkObject      *obj,
-                                                            gint           i);
-static AtkStateSet*          gail_menu_item_ref_state_set  (AtkObject      *obj);
-static void                  gail_menu_item_finalize       (GObject        *object);
-static void                  gail_menu_item_label_map_gtk  (GtkWidget     *widget,
-                                                            gpointer       data);
-static void                  gail_menu_item_init_textutil  (GailMenuItem  *item,
-                                                            GtkWidget     *label);
-static void                  gail_menu_item_notify_label_gtk (GObject       *obj,
-                                                              GParamSpec    *pspec,
-                                                              gpointer      data);
-static const gchar *         gail_menu_item_get_name         (AtkObject    *object);
-
-
-static void                  atk_action_interface_init     (AtkActionIface *iface);
-static gboolean              gail_menu_item_do_action      (AtkAction      *action,
-                                                            gint           i);
-static gint                  gail_menu_item_get_n_actions  (AtkAction      *action);
-static const gchar* gail_menu_item_action_get_name (AtkAction      *action,
-                                                             gint           i);
-static const gchar* gail_menu_item_get_keybinding (AtkAction      *action,
-                                                            gint           i);
-static void                  menu_item_select              (GtkMenuItem        *item);
-static void                  menu_item_deselect            (GtkMenuItem        *item);
-static void                  menu_item_selection           (GtkMenuItem        *item,
-                                                            gboolean       selected);
-static gboolean              find_accel                    (GtkAccelKey    *key,
-                                                            GClosure       *closure,
-                                                            gpointer       data);
-static gboolean              find_accel_new                (GtkAccelKey    *key,
-                                                            GClosure       *closure,
-                                                            gpointer       data);
-
-static GtkWidget*       get_label_from_container   (GtkWidget    *container);
-static gchar *          get_text_from_label_widget (GtkWidget    *widget);
-
-
-G_DEFINE_TYPE_WITH_CODE (GailMenuItem, gail_menu_item, GAIL_TYPE_CONTAINER,
-                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
-
-static void
-gail_menu_item_class_init (GailMenuItemClass *klass)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
-
-  gobject_class->finalize = gail_menu_item_finalize;
-
-  class->get_n_children = gail_menu_item_get_n_children;
-  class->ref_child = gail_menu_item_ref_child;
-  class->ref_state_set = gail_menu_item_ref_state_set;
-  class->initialize = gail_menu_item_real_initialize;
-  class->get_name = gail_menu_item_get_name;
-}
-
-static void
-gail_menu_item_real_initialize (AtkObject *obj,
-                                gpointer  data)
-{
-  GtkWidget *widget;
-  GtkWidget *parent;
-  GailMenuItem *item = GAIL_MENU_ITEM (obj);
-  GtkWidget *label;
-
-  ATK_OBJECT_CLASS (gail_menu_item_parent_class)->initialize (obj, data);
-
-  item->textutil = NULL;
-  item->text = NULL;
-
-  label = get_label_from_container (GTK_WIDGET (data));
-  if (gtk_widget_get_mapped (label))
-    gail_menu_item_init_textutil (item, label);
-  else
-    g_signal_connect (label,
-                      "map",
-                      G_CALLBACK (gail_menu_item_label_map_gtk),
-                      item);
-
-  g_signal_connect (data,
-                    "select",
-                    G_CALLBACK (menu_item_select),
-                    NULL);
-  g_signal_connect (data,
-                    "deselect",
-                    G_CALLBACK (menu_item_deselect),
-                    NULL);
-  widget = GTK_WIDGET (data);
-  parent = gtk_widget_get_parent (widget);
-  if (GTK_IS_MENU (parent))
-    {
-      GtkWidget *parent_widget;
-
-      parent_widget =  gtk_menu_get_attach_widget (GTK_MENU (parent));
-
-      if (!GTK_IS_MENU_ITEM (parent_widget))
-        parent_widget = gtk_widget_get_parent (widget);
-       if (parent_widget)
-        {
-          atk_object_set_parent (obj, gtk_widget_get_accessible (parent_widget));
-        }
-    }
-  g_object_set_data (G_OBJECT (obj), "atk-component-layer",
-                     GINT_TO_POINTER (ATK_LAYER_POPUP));
-
-  if (GTK_IS_TEAROFF_MENU_ITEM (data))
-    obj->role = ATK_ROLE_TEAR_OFF_MENU_ITEM;
-  else if (GTK_IS_SEPARATOR_MENU_ITEM (data))
-    obj->role = ATK_ROLE_SEPARATOR;
-  else
-    obj->role = ATK_ROLE_MENU_ITEM;
-}
-
-static void
-gail_menu_item_init (GailMenuItem *menu_item)
-{
-  menu_item->click_keybinding = NULL;
-}
-
-static void
-gail_menu_item_label_map_gtk (GtkWidget *widget,
-                              gpointer data)
-{
-  GailMenuItem *item;
-
-  item = GAIL_MENU_ITEM (data);
-  gail_menu_item_init_textutil (item, widget);
-}
-
-static void
-gail_menu_item_notify_label_gtk (GObject           *obj,
-                                 GParamSpec        *pspec,
-                                 gpointer           data)
-{
-  AtkObject* atk_obj = ATK_OBJECT (data);
-  GtkLabel *label;
-  GailMenuItem *menu_item;
-
-  if (strcmp (pspec->name, "label") == 0)
-    {
-      const gchar* label_text;
-
-      label = GTK_LABEL (obj);
-
-      label_text = gtk_label_get_text (label);
-
-      menu_item = GAIL_MENU_ITEM (atk_obj);
-      gail_text_util_text_setup (menu_item->textutil, label_text);
-
-      if (atk_obj->name == NULL)
-      {
-        /*
-         * The label has changed so notify a change in accessible-name
-         */
-        g_object_notify (G_OBJECT (atk_obj), "accessible-name");
-      }
-      /*
-       * The label is the only property which can be changed
-       */
-      g_signal_emit_by_name (atk_obj, "visible_data_changed");
-    }
-}
-
-static void
-gail_menu_item_init_textutil (GailMenuItem  *item,
-                              GtkWidget *label)
-{
-  gchar *label_text;
-
-  if (item->textutil == NULL)
-    {
-      item->textutil = gail_text_util_new ();
-      g_signal_connect (label,
-                        "notify",
-                        (GCallback) gail_menu_item_notify_label_gtk,
-                        item);     
-    }
-  label_text = get_text_from_label_widget (label);
-  gail_text_util_text_setup (item->textutil, label_text ? label_text : "");
-  g_free (label_text);
-}
-
-static GtkWidget*
-get_label_from_container (GtkWidget *container)
-{
-  GtkWidget *label;
-  GList *children, *tmp_list;
-
-  if (!GTK_IS_CONTAINER (container))
-    return NULL;
-  children = gtk_container_get_children (GTK_CONTAINER (container));
-  label = NULL;
-
-  for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next) 
-    {
-      if (GTK_IS_LABEL (tmp_list->data))
-        {
-          label = tmp_list->data;
-          break;
-        }
-      else if (GTK_IS_CELL_VIEW (tmp_list->data))
-        {
-          label = tmp_list->data;
-          break;
-        }
-      /*
- *        * Get label from menu item in desktop background preferences
- *               * option menu. See bug #144084.
- *                      */
-      else if (GTK_IS_BOX (tmp_list->data))
-        {
-          label = get_label_from_container (GTK_WIDGET (tmp_list->data));
-          if (label)
-            break;
-        }
-    }
-  g_list_free (children);
-
-  return label;
-}
-
-static gchar *
-get_text_from_label_widget (GtkWidget *label)
-{
-  if (GTK_IS_LABEL (label))
-    return g_strdup (gtk_label_get_text (GTK_LABEL (label)));
-  else if (GTK_IS_CELL_VIEW (label))
-    {
-      GList *cells, *l;
-      GtkTreeModel *model;
-      GtkTreeIter iter;
-      GtkTreePath *path;
-      GtkCellArea *area;
-      gchar *text;
-
-      model = gtk_cell_view_get_model (GTK_CELL_VIEW (label));
-      path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (label));
-      gtk_tree_model_get_iter (model, &iter, path);
-      gtk_tree_path_free (path);
-
-      area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (label));
-
-      gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
-
-      cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (label));
-      for (l = cells; l; l = l->next)
-        {
-          GtkCellRenderer *cell = l->data;
-
-          if (GTK_IS_CELL_RENDERER_TEXT (cell))
-            {
-              g_object_get (cell, "text", &text, NULL);
-              break;
-            }
-        }
-
-      g_list_free (cells);
-
-      return text;
-    }
-
-  return NULL;
-}
-
-AtkObject*
-gail_menu_item_new (GtkWidget *widget)
-{
-  GObject *object;
-  AtkObject *accessible;
-  
-  g_return_val_if_fail (GTK_IS_MENU_ITEM (widget), NULL);
-
-  if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)))
-    return gail_sub_menu_item_new (widget);
-
-  object = g_object_new (GAIL_TYPE_MENU_ITEM, NULL);
-
-  accessible = ATK_OBJECT (object);
-  atk_object_initialize (accessible, widget);
-
-  return accessible;
-}
-
-GList *
-get_children (GtkWidget *submenu)
-{
-  GList *children;
-
-  children = gtk_container_get_children (GTK_CONTAINER (submenu));
-  if (g_list_length (children) == 0)
-    {
-      /*
-       * If menu is empty it may be because the menu items are created only 
-       * on demand. For example, in gnome-panel the menu items are created
-       * only when "show" signal is emitted on the menu.
-       *
-       * The following hack forces the menu items to be created.
-       */
-      if (!gtk_widget_get_visible (submenu))
-        {
-          /* FIXME GTK_WIDGET_SET_FLAGS (submenu, GTK_VISIBLE); */
-          g_signal_emit_by_name (submenu, "show");
-          /* FIXME GTK_WIDGET_UNSET_FLAGS (submenu, GTK_VISIBLE); */
-        }
-      g_list_free (children);
-      children = gtk_container_get_children (GTK_CONTAINER (submenu));
-    }
-  return children;
-}
-
-/*
- * If a menu item has a submenu return the items of the submenu as the 
- * accessible children; otherwise expose no accessible children.
- */
-static gint
-gail_menu_item_get_n_children (AtkObject* obj)
-{
-  GtkWidget *widget;
-  GtkWidget *submenu;
-  gint count = 0;
-
-  g_return_val_if_fail (GAIL_IS_MENU_ITEM (obj), count);
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-  if (widget == NULL)
-    return count;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  if (submenu)
-    {
-      GList *children;
-
-      children = get_children (submenu);
-      count = g_list_length (children);
-      g_list_free (children);
-    }
-  return count;
-}
-
-static AtkObject*
-gail_menu_item_ref_child (AtkObject *obj,
-                          gint       i)
-{
-  AtkObject  *accessible;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-
-  g_return_val_if_fail (GAIL_IS_MENU_ITEM (obj), NULL);
-  g_return_val_if_fail ((i >= 0), NULL);
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-  if (widget == NULL)
-    return NULL;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  if (submenu)
-    {
-      GList *children;
-      GList *tmp_list;
-
-      children = get_children (submenu);
-      tmp_list = g_list_nth (children, i);
-      if (!tmp_list)
-        {
-          g_list_free (children);
-          return NULL;
-        }
-      accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
-      g_list_free (children);
-      g_object_ref (accessible);
-    }
-  else
-    accessible = NULL;
-
-  return accessible;
-}
-
-static AtkStateSet*
-gail_menu_item_ref_state_set (AtkObject *obj)
-{
-  AtkObject *menu_item;
-  AtkStateSet *state_set, *parent_state_set;
-
-  state_set = ATK_OBJECT_CLASS (gail_menu_item_parent_class)->ref_state_set (obj);
-
-  menu_item = atk_object_get_parent (obj);
-
-  if (menu_item)
-    {
-      if (!GTK_IS_MENU_ITEM (gtk_accessible_get_widget (GTK_ACCESSIBLE (menu_item))))
-        return state_set;
-
-      parent_state_set = atk_object_ref_state_set (menu_item);
-      if (!atk_state_set_contains_state (parent_state_set, ATK_STATE_SELECTED))
-        {
-          atk_state_set_remove_state (state_set, ATK_STATE_FOCUSED);
-          atk_state_set_remove_state (state_set, ATK_STATE_SHOWING);
-        }
-    }
-  return state_set;
-}
-
-static void
-atk_action_interface_init (AtkActionIface *iface)
-{
-  iface->do_action = gail_menu_item_do_action;
-  iface->get_n_actions = gail_menu_item_get_n_actions;
-  iface->get_name = gail_menu_item_action_get_name;
-  iface->get_keybinding = gail_menu_item_get_keybinding;
-}
-
-static void
-ensure_menus_unposted (GailMenuItem *menu_item)
-{
-  AtkObject *parent;
-  GtkWidget *widget;
-
-  parent = atk_object_get_parent (ATK_OBJECT (menu_item));
-  while (parent)
-    {
-      widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
-      if (GTK_IS_MENU (widget))
-        {
-          if (gtk_widget_get_mapped (widget))
-            gtk_menu_shell_cancel (GTK_MENU_SHELL (widget));
-
-          return;
-        }
-      parent = atk_object_get_parent (parent);
-    }
-}
-
-static gboolean
-gail_menu_item_do_action (AtkAction *action,
-                          gint      i)
-{
-  if (i == 0)
-    {
-      GtkWidget *item, *item_parent;
-      gboolean item_mapped;
-
-      item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
-      if (item == NULL)
-        /* State is defunct */
-        return FALSE;
-
-      if (!gtk_widget_get_sensitive (item) || !gtk_widget_get_visible (item))
-        return FALSE;
-
-      item_parent = gtk_widget_get_parent (item);
-      if (!GTK_IS_MENU_SHELL (item_parent))
-        return FALSE;
-
-      gtk_menu_shell_select_item (GTK_MENU_SHELL (item_parent), item);
-      item_mapped = gtk_widget_get_mapped (item);
-      /*
-       * This is what is called when <Return> is pressed for a menu item
-       */
-      g_signal_emit_by_name (item_parent, "activate_current",  
-                             /*force_hide*/ 1); 
-      if (!item_mapped)
-        ensure_menus_unposted (GAIL_MENU_ITEM (action));
-
-      return TRUE;
-    }
-  else
-    return FALSE;
-}
-
-static gint
-gail_menu_item_get_n_actions (AtkAction *action)
-{
-  /*
-   * Menu item has 1 action
-   */
-  return 1;
-}
-
-static const gchar*
-gail_menu_item_action_get_name (AtkAction *action,
-                                gint      i)
-{
-  if (i == 0)
-    return "click";
-  else
-    return NULL;
-}
-
-static const gchar*
-gail_menu_item_get_keybinding (AtkAction *action,
-                               gint      i)
-{
-  /*
-   * This function returns a string of the form A;B;C where
-   * A is the keybinding for the widget; B is the keybinding to traverse
-   * from the menubar and C is the accelerator.
-   * The items in the keybinding to traverse from the menubar are separated
-   * by ":".
-   */
-  GailMenuItem  *gail_menu_item;
-  gchar *keybinding = NULL;
-  gchar *item_keybinding = NULL;
-  gchar *full_keybinding = NULL;
-  gchar *accelerator = NULL;
-
-  gail_menu_item = GAIL_MENU_ITEM (action);
-  if (i == 0)
-    {
-      GtkWidget *item;
-      GtkWidget *temp_item;
-      GtkWidget *child;
-      GtkWidget *parent;
-
-      item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
-      if (item == NULL)
-        /* State is defunct */
-        return NULL;
-
-      temp_item = item;
-      while (TRUE)
-        {
-          GdkModifierType mnemonic_modifier = 0;
-          guint key_val;
-          gchar *key, *temp_keybinding;
-
-          child = gtk_bin_get_child (GTK_BIN (temp_item));
-          if (child == NULL)
-            {
-              /* Possibly a tear off menu item; it could also be a menu 
-               * separator generated by gtk_item_factory_create_items()
-               */
-              return NULL;
-            }
-          parent = gtk_widget_get_parent (temp_item);
-          if (!parent)
-            {
-              /*
-               * parent can be NULL when activating a window from the panel
-               */
-              return NULL;
-            }
-          g_return_val_if_fail (GTK_IS_MENU_SHELL (parent), NULL);
-          if (GTK_IS_MENU_BAR (parent))
-            {
-              GtkWidget *toplevel;
-
-              toplevel = gtk_widget_get_toplevel (parent);
-              if (toplevel && GTK_IS_WINDOW (toplevel))
-                mnemonic_modifier = gtk_window_get_mnemonic_modifier (
-                                       GTK_WINDOW (toplevel));
-            }
-          if (GTK_IS_LABEL (child))
-            {
-              key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
-              if (key_val != GDK_KEY_VoidSymbol)
-                {
-                  key = gtk_accelerator_name (key_val, mnemonic_modifier);
-                  if (full_keybinding)
-                    temp_keybinding = g_strconcat (key, ":", full_keybinding, NULL);
-                  else 
-                    temp_keybinding = g_strconcat (key, NULL);
-                  if (temp_item == item)
-                    {
-                      item_keybinding = g_strdup (key); 
-                    }
-                  g_free (key);
-                  g_free (full_keybinding);
-                  full_keybinding = temp_keybinding;
-                }
-              else
-                {
-                  /* No keybinding */
-                  g_free (full_keybinding);
-                  full_keybinding = NULL;
-                  break;
-                }        
-            }        
-          if (GTK_IS_MENU_BAR (parent))
-            /* We have reached the menu bar so we are finished */
-            break;
-          g_return_val_if_fail (GTK_IS_MENU (parent), NULL);
-          temp_item = gtk_menu_get_attach_widget (GTK_MENU (parent));
-          if (!GTK_IS_MENU_ITEM (temp_item))
-            {
-              /* 
-               * Menu is attached to something other than a menu item;
-               * probably an option menu
-               */
-              g_free (full_keybinding);
-              full_keybinding = NULL;
-              break;
-            }
-        }
-
-      parent = gtk_widget_get_parent (item);
-      if (GTK_IS_MENU (parent))
-        {
-          GtkAccelGroup *group; 
-          GtkAccelKey *key;
-
-          group = gtk_menu_get_accel_group (GTK_MENU (parent));
-
-          if (group)
-            {
-              key = gtk_accel_group_find (group, find_accel, item);
-            }
-          else
-            {
-              /*
-               * If the menu item is created using GtkAction and GtkUIManager
-               * we get here.
-               */
-              key = NULL;
-              child = gtk_bin_get_child (GTK_BIN (item));
-              if (GTK_IS_ACCEL_LABEL (child))
-                {
-                  GtkAccelLabel *accel_label;
-                  GClosure      *accel_closure;
-
-                  accel_label = GTK_ACCEL_LABEL (child);
-                  g_object_get (accel_label,
-                                "accel-closure", &accel_closure,
-                                NULL);
-                  if (accel_closure)
-                    {
-                      key = gtk_accel_group_find (gtk_accel_group_from_accel_closure (accel_closure),
-                                                  find_accel_new,
-                                                  accel_closure);
-                    }
-               
-                }
-            }
-
-          if (key)
-            {           
-              accelerator = gtk_accelerator_name (key->accel_key,
-                                                  key->accel_mods);
-            }
-        }
-    }
-  /*
-   * Concatenate the bindings
-   */
-  if (item_keybinding || full_keybinding || accelerator)
-    {
-      gchar *temp;
-      if (item_keybinding)
-        {
-          keybinding = g_strconcat (item_keybinding, KEYBINDING_SEPARATOR, NULL);
-          g_free (item_keybinding);
-        }
-      else
-        keybinding = g_strconcat (KEYBINDING_SEPARATOR, NULL);
-
-      if (full_keybinding)
-        {
-          temp = g_strconcat (keybinding, full_keybinding, 
-                              KEYBINDING_SEPARATOR, NULL);
-          g_free (full_keybinding);
-        }
-      else
-        temp = g_strconcat (keybinding, KEYBINDING_SEPARATOR, NULL);
-
-      g_free (keybinding);
-      keybinding = temp;
-      if (accelerator)
-        {
-          temp = g_strconcat (keybinding, accelerator, NULL);
-          g_free (accelerator);
-          g_free (keybinding);
-          keybinding = temp;
-      }
-    }
-  g_free (gail_menu_item->click_keybinding);
-  gail_menu_item->click_keybinding = keybinding;
-  return keybinding;
-}
-
-static void
-gail_menu_item_finalize (GObject *object)
-{
-  GailMenuItem *menu_item = GAIL_MENU_ITEM (object);
-
-  g_free (menu_item->click_keybinding);
-  if (menu_item->textutil)
-    {
-      g_object_unref (menu_item->textutil);
-    }
-  if (menu_item->text)
-    {
-      g_free (menu_item->text);
-      menu_item->text = NULL;
-    }
-
-  G_OBJECT_CLASS (gail_menu_item_parent_class)->finalize (object);
-}
-
-static const gchar *
-gail_menu_item_get_name (AtkObject *obj)
-{
-  const gchar* name;
-  GtkWidget *widget;
-  GtkWidget *label;
-
-  name = ATK_OBJECT_CLASS (gail_menu_item_parent_class)->get_name (obj);
-
-  if (name)
-    return name;
-
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-  if (widget == NULL)
-    return NULL;
-
-  label = get_label_from_container (widget);
-  if (GTK_IS_LABEL (label))
-    return gtk_label_get_text (GTK_LABEL(label));
-
-  return NULL;
-}
-
-static void
-menu_item_select (GtkMenuItem *item)
-{
-  menu_item_selection (item, TRUE);
-}
-
-static void
-menu_item_deselect (GtkMenuItem *item)
-{
-  menu_item_selection (item, FALSE);
-}
-
-static void
-menu_item_selection (GtkMenuItem  *item,
-                     gboolean selected)
-{
-  AtkObject *obj, *parent;
-  gint i;
-
-  obj = gtk_widget_get_accessible (GTK_WIDGET (item));
-  atk_object_notify_state_change (obj, ATK_STATE_SELECTED, selected);
-
-  for (i = 0; i < atk_object_get_n_accessible_children (obj); i++)
-    {
-      AtkObject *child;
-      child = atk_object_ref_accessible_child (obj, i);
-      atk_object_notify_state_change (child, ATK_STATE_SHOWING, selected);
-      g_object_unref (child);
-    }
-  parent = atk_object_get_parent (obj);
-  g_signal_emit_by_name (parent, "selection_changed"); 
-}
-
-static gboolean
-find_accel (GtkAccelKey *key,
-            GClosure    *closure,
-            gpointer     data)
-{
-  /*
-   * We assume that closure->data points to the widget
-   * pending gtk_widget_get_accel_closures being made public
-   */
-  return data == (gpointer) closure->data;
-}
-
-static gboolean
-find_accel_new (GtkAccelKey *key,
-                GClosure    *closure,
-                gpointer     data)
-{
-  return data == (gpointer) closure;
-}
diff --git a/gtk/a11y/gailmenuitem.h b/gtk/a11y/gailmenuitem.h
deleted file mode 100644 (file)
index 16bf09b..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/* GAIL - The GNOME Accessibility Implementation Library
- * Copyright 2001 Sun Microsystems Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GAIL_MENU_ITEM_H__
-#define __GAIL_MENU_ITEM_H__
-
-#include "gailcontainer.h"
-#include "gailtextutil.h"
-
-G_BEGIN_DECLS
-
-#define GAIL_TYPE_MENU_ITEM                     (gail_menu_item_get_type ())
-#define GAIL_MENU_ITEM(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_MENU_ITEM, GailMenuItem))
-#define GAIL_MENU_ITEM_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_MENU_ITEM, GailMenuItemClass))
-#define GAIL_IS_MENU_ITEM(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_MENU_ITEM))
-#define GAIL_IS_MENU_ITEM_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_MENU_ITEM))
-#define GAIL_MENU_ITEM_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_MENU_ITEM, GailMenuItemClass))
-
-typedef struct _GailMenuItem                   GailMenuItem;
-typedef struct _GailMenuItemClass              GailMenuItemClass;
-
-struct _GailMenuItem
-{
-  GailContainer parent;
-
-  GailTextUtil *textutil;
-
-  gchar *text;
-
-  gchar    *click_keybinding;
-};
-
-GType gail_menu_item_get_type (void);
-
-struct _GailMenuItemClass
-{
-  GailContainerClass parent_class;
-};
-
-AtkObject* gail_menu_item_new (GtkWidget *widget);
-
-G_END_DECLS
-
-#endif /* __GAIL_MENU_ITEM_H__ */
diff --git a/gtk/a11y/gailsubmenuitem.c b/gtk/a11y/gailsubmenuitem.c
deleted file mode 100644 (file)
index a571f98..0000000
+++ /dev/null
@@ -1,362 +0,0 @@
-/* GAIL - The GNOME Accessibility Implementation Library
- * Copyright 2002, 2003 Sun Microsystems Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <gtk/gtk.h>
-#include "gailsubmenuitem.h"
-
-static void         gail_sub_menu_item_class_init       (GailSubMenuItemClass *klass);
-static void         gail_sub_menu_item_init             (GailSubMenuItem *item);
-static void         gail_sub_menu_item_real_initialize  (AtkObject      *obj,
-                                                         gpointer       data);
-
-static void         atk_selection_interface_init        (AtkSelectionIface  *iface);
-static gboolean     gail_sub_menu_item_add_selection    (AtkSelection   *selection,
-                                                         gint           i);
-static gboolean     gail_sub_menu_item_clear_selection  (AtkSelection   *selection);
-static AtkObject*   gail_sub_menu_item_ref_selection    (AtkSelection   *selection,
-                                                         gint           i);
-static gint         gail_sub_menu_item_get_selection_count
-                                                        (AtkSelection   *selection);
-static gboolean     gail_sub_menu_item_is_child_selected
-                                                        (AtkSelection   *selection,
-                                                         gint           i);
-static gboolean     gail_sub_menu_item_remove_selection (AtkSelection   *selection,
-                                                         gint           i);
-static gint         menu_item_add_gtk                   (GtkContainer   *container,
-                                                         GtkWidget      *widget);
-static gint         menu_item_remove_gtk                (GtkContainer   *container,
-                                                         GtkWidget      *widget);
-
-G_DEFINE_TYPE_WITH_CODE (GailSubMenuItem, gail_sub_menu_item, GAIL_TYPE_MENU_ITEM,
-                         G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
-
-static void
-gail_sub_menu_item_class_init (GailSubMenuItemClass *klass)
-{
-  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
-
-  class->initialize = gail_sub_menu_item_real_initialize;
-}
-
-static void
-gail_sub_menu_item_init (GailSubMenuItem *item)
-{
-}
-
-static void
-gail_sub_menu_item_real_initialize (AtkObject *obj,
-                                   gpointer   data)
-{
-  GtkWidget *submenu;
-
-  ATK_OBJECT_CLASS (gail_sub_menu_item_parent_class)->initialize (obj, data);
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (data));
-  g_return_if_fail (submenu);
-
-  g_signal_connect (submenu,
-                    "add",
-                    G_CALLBACK (menu_item_add_gtk),
-                    NULL);
-  g_signal_connect (submenu,
-                    "remove",
-                    G_CALLBACK (menu_item_remove_gtk),
-                    NULL);
-
-  obj->role = ATK_ROLE_MENU;
-}
-
-AtkObject*
-gail_sub_menu_item_new (GtkWidget *widget)
-{
-  GObject *object;
-  AtkObject *accessible;
-
-  g_return_val_if_fail (GTK_IS_MENU_ITEM (widget), NULL);
-
-  object = g_object_new (GAIL_TYPE_SUB_MENU_ITEM, NULL);
-
-  accessible = ATK_OBJECT (object);
-  atk_object_initialize (accessible, widget);
-
-  return accessible;
-}
-
-static void
-atk_selection_interface_init (AtkSelectionIface *iface)
-{
-  iface->add_selection = gail_sub_menu_item_add_selection;
-  iface->clear_selection = gail_sub_menu_item_clear_selection;
-  iface->ref_selection = gail_sub_menu_item_ref_selection;
-  iface->get_selection_count = gail_sub_menu_item_get_selection_count;
-  iface->is_child_selected = gail_sub_menu_item_is_child_selected;
-  iface->remove_selection = gail_sub_menu_item_remove_selection;
-  /*
-   * select_all_selection does not make sense for a submenu of a menu item
-   * so no implementation is provided.
-   */
-}
-
-static gboolean
-gail_sub_menu_item_add_selection (AtkSelection *selection,
-                                  gint          i)
-{
-  GtkMenuShell *shell;
-  GList *kids;
-  guint length;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-  GtkWidget *child;
-
-  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-  if (widget == NULL)
-    /* State is defunct */
-    return FALSE;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
-  shell = GTK_MENU_SHELL (submenu);
-  kids = gtk_container_get_children (GTK_CONTAINER (shell));
-  length = g_list_length (kids);
-  if (i < 0 || i > length)
-    {
-      g_list_free (kids);
-      return FALSE;
-    }
-
-  child = g_list_nth_data (kids, i);
-  g_list_free (kids);
-  g_return_val_if_fail (GTK_IS_MENU_ITEM(child), FALSE);
-  gtk_menu_shell_select_item (shell, GTK_WIDGET (child));
-  return TRUE;
-}
-
-static gboolean
-gail_sub_menu_item_clear_selection (AtkSelection   *selection)
-{
-  GtkMenuShell *shell;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-
-  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-  if (widget == NULL)
-    /* State is defunct */
-    return FALSE;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
-  shell = GTK_MENU_SHELL (submenu);
-
-  gtk_menu_shell_deselect (shell);
-  return TRUE;
-}
-
-static AtkObject*
-gail_sub_menu_item_ref_selection (AtkSelection   *selection,
-                                  gint           i)
-{
-  GtkMenuShell *shell;
-  AtkObject *obj;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-  GtkWidget *item;
-
-  if (i != 0)
-    return NULL;
-
-  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-  if (widget == NULL)
-    /* State is defunct */
-    return NULL;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), NULL);
-  shell = GTK_MENU_SHELL (submenu);
-
-  item = gtk_menu_shell_get_selected_item (shell);
-  if (item != NULL)
-    {
-      obj = gtk_widget_get_accessible (item);
-      g_object_ref (obj);
-      return obj;
-    }
-  else
-    {
-      return NULL;
-    }
-}
-
-static gint
-gail_sub_menu_item_get_selection_count (AtkSelection   *selection)
-{
-  GtkMenuShell *shell;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-
-  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-  if (widget == NULL)
-    /* State is defunct */
-    return 0;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
-  shell = GTK_MENU_SHELL (submenu);
-
-  /*
-   * Identifies the currently selected menu item
-   */
-  if (gtk_menu_shell_get_selected_item (shell) == NULL)
-    return 0;
-  else
-    return 1;
-}
-
-static gboolean
-gail_sub_menu_item_is_child_selected (AtkSelection   *selection,
-                                       gint           i)
-{
-  GtkMenuShell *shell;
-  gint j;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-  GtkWidget *item;
-  GList *kids;
-
-  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-  if (widget == NULL)
-    /* State is defunct */
-    return FALSE;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
-  shell = GTK_MENU_SHELL (submenu);
-
-  item = gtk_menu_shell_get_selected_item (shell);
-  if (item == NULL)
-    return FALSE;
-
-  kids = gtk_container_get_children (GTK_CONTAINER (shell));
-  j = g_list_index (kids, item);
-  g_list_free (kids);
-
-  return (j==i);
-}
-
-static gboolean
-gail_sub_menu_item_remove_selection (AtkSelection   *selection,
-                                  gint           i)
-{
-  GtkMenuShell *shell;
-  GtkWidget *widget;
-  GtkWidget *submenu;
-  GtkWidget *item;
-
-  if (i != 0)
-    return FALSE;
-
-  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
-  if (widget == NULL)
-    /* State is defunct */
-    return FALSE;
-
-  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
-  shell = GTK_MENU_SHELL (submenu);
-
-  item = gtk_menu_shell_get_selected_item (shell);
-  if (item && gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
-    {
-    /*
-     * Menu item contains a menu and it is the selected menu item
-     * so deselect it.
-     */
-      gtk_menu_shell_deselect (shell);
-    }
-  return TRUE;
-}
-
-static gint
-menu_item_add_gtk (GtkContainer *container,
-                   GtkWidget   *widget)
-{
-  GtkWidget *parent_widget;
-  AtkObject *atk_parent;
-  AtkObject *atk_child;
-  GailContainer *gail_container;
-  gint index;
-
-  g_return_val_if_fail (GTK_IS_MENU (container), 1);
-
-  parent_widget = gtk_menu_get_attach_widget (GTK_MENU (container));
-  if (GTK_IS_MENU_ITEM (parent_widget))
-    {
-      atk_parent = gtk_widget_get_accessible (parent_widget);
-      atk_child = gtk_widget_get_accessible (widget);
-
-      gail_container = GAIL_CONTAINER (atk_parent);
-      g_object_notify (G_OBJECT (atk_child), "accessible_parent");
-
-      g_list_free (gail_container->children);
-      gail_container->children = gtk_container_get_children (container);
-      index = g_list_index (gail_container->children, widget);
-      g_signal_emit_by_name (atk_parent, "children_changed::add",
-                             index, atk_child, NULL);
-    }
-  return 1;
-}
-
-static gint
-menu_item_remove_gtk (GtkContainer *container,
-                      GtkWidget           *widget)
-{
-  GtkWidget *parent_widget;
-  AtkObject *atk_parent;
-  AtkObject *atk_child;
-  GailContainer *gail_container;
-  AtkPropertyValues values = { NULL };
-  gint index;
-  gint list_length;
-
-  g_return_val_if_fail (GTK_IS_MENU (container), 1);
-
-  parent_widget = gtk_menu_get_attach_widget (GTK_MENU (container));
-  if (GTK_IS_MENU_ITEM (parent_widget))
-    {
-      atk_parent = gtk_widget_get_accessible (parent_widget);
-      atk_child = gtk_widget_get_accessible (widget);
-
-      gail_container = GAIL_CONTAINER (atk_parent);
-      g_value_init (&values.old_value, G_TYPE_POINTER);
-      g_value_set_pointer (&values.old_value, atk_parent);
-      values.property_name = "accessible-parent";
-      g_signal_emit_by_name (atk_child,
-                             "property_change::accessible-parent", &values, NULL);
-
-      index = g_list_index (gail_container->children, widget);
-      list_length = g_list_length (gail_container->children);
-      g_list_free (gail_container->children);
-      gail_container->children = gtk_container_get_children (container);
-      if (index >= 0 && index <= list_length)
-        g_signal_emit_by_name (atk_parent, "children_changed::remove",
-                               index, atk_child, NULL);
-    }
-  return 1;
-}
diff --git a/gtk/a11y/gailsubmenuitem.h b/gtk/a11y/gailsubmenuitem.h
deleted file mode 100644 (file)
index 9f839c3..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/* GAIL - The GNOME Accessibility Implementation Library
- * Copyright 2002 Sun Microsystems Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GAIL_SUB_MENU_ITEM_H__
-#define __GAIL_SUB_MENU_ITEM_H__
-
-#include "gailmenuitem.h"
-
-G_BEGIN_DECLS
-
-#define GAIL_TYPE_SUB_MENU_ITEM                     (gail_sub_menu_item_get_type ())
-#define GAIL_SUB_MENU_ITEM(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_SUB_MENU_ITEM, GailSubMenuItem))
-#define GAIL_SUB_MENU_ITEM_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_SUB_MENU_ITEM, GailSubMenuItemClass))
-#define GAIL_IS_SUB_MENU_ITEM(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_SUB_MENU_ITEM))
-#define GAIL_IS_SUB_MENU_ITEM_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_SUB_MENU_ITEM))
-#define GAIL_SUB_MENU_ITEM_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_SUB_MENU_ITEM, GailSubMenuItemClass))
-
-typedef struct _GailSubMenuItem                   GailSubMenuItem;
-typedef struct _GailSubMenuItemClass              GailSubMenuItemClass;
-
-struct _GailSubMenuItem
-{
-  GailMenuItem parent;
-
-};
-
-GType gail_sub_menu_item_get_type (void);
-
-struct _GailSubMenuItemClass
-{
-  GailMenuItemClass parent_class;
-};
-
-AtkObject* gail_sub_menu_item_new (GtkWidget *widget);
-
-G_END_DECLS
-
-#endif /* __GAIL_SUB_MENU_ITEM_H__ */
index 7eb9b0f05cb15e61c8911c313e3decfca8bf6059..7348275a4c10365a6d1773a119896adbce569607 100644 (file)
@@ -23,7 +23,7 @@
 #include "gtkcheckmenuitemaccessible.h"
 
 
-G_DEFINE_TYPE (GtkCheckMenuItemAccessible, gtk_check_menu_item_accessible, GAIL_TYPE_MENU_ITEM)
+G_DEFINE_TYPE (GtkCheckMenuItemAccessible, gtk_check_menu_item_accessible, GTK_TYPE_MENU_ITEM_ACCESSIBLE)
 
 static void
 toggled_cb (GtkWidget *widget)
index 8749030df820b3cb3eb1fb510aa299da4b9b53e9..2adc4246ee7992e60d362f163601bb8d50e7a21d 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef __GTK_CHECK_MENU_ITEM_ACCESSIBLE_H__
 #define __GTK_CHECK_MENU_ITEM_ACCESSIBLE_H__
 
-#include "gailmenuitem.h"
+#include "gtkmenuitemaccessible.h"
 
 G_BEGIN_DECLS
 
@@ -36,12 +36,12 @@ typedef struct _GtkCheckMenuItemAccessibleClass GtkCheckMenuItemAccessibleClass;
 
 struct _GtkCheckMenuItemAccessible
 {
-  GailMenuItem parent;
+  GtkMenuItemAccessible parent;
 };
 
 struct _GtkCheckMenuItemAccessibleClass
 {
-  GailMenuItemClass parent_class;
+  GtkMenuItemAccessibleClass parent_class;
 };
 
 GType gtk_check_menu_item_accessible_get_type (void);
index fe6681b877ece40d344f7af8fae65197eefe42b4..eb55c587c3ece96573cf72193b5f7985fd0212bf 100644 (file)
@@ -24,7 +24,7 @@
 #include "gtkchecksubmenuitemaccessible.h"
 
 
-G_DEFINE_TYPE (GtkCheckSubmenuItemAccessible, gtk_check_submenu_item_accessible, GAIL_TYPE_SUB_MENU_ITEM)
+G_DEFINE_TYPE (GtkCheckSubmenuItemAccessible, gtk_check_submenu_item_accessible, GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE)
 
 static void
 toggled_cb (GtkWidget *widget)
index 91065fcf1c95c6269fb1749c857f8a49d59337e5..bc4e8c375c82bdc04316fb1dd406ca1abcc3fb53 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef __GTK_CHECK_SUBMENU_ITEM_ACCESSIBLE_H__
 #define __GTK_CHECK_SUBMENU_ITEM_ACCESSIBLE_H__
 
-#include "gailsubmenuitem.h"
+#include "gtksubmenuitemaccessible.h"
 
 G_BEGIN_DECLS
 
@@ -36,12 +36,12 @@ typedef struct _GtkCheckSubmenuItemAccessibleClass GtkCheckSubmenuItemAccessible
 
 struct _GtkCheckSubmenuItemAccessible
 {
-  GailSubMenuItem parent;
+  GtkSubmenuItemAccessible parent;
 };
 
 struct _GtkCheckSubmenuItemAccessibleClass
 {
-  GailSubMenuItemClass parent_class;
+  GtkSubmenuItemAccessibleClass parent_class;
 };
 
 GType gtk_check_submenu_item_accessible_get_type (void);
index 105dfac2fea36ba7713d9ba88149b0a092f80ec9..ab599f9d24d28d9c8b73252a201ca155b0937463 100644 (file)
@@ -243,7 +243,6 @@ static const gchar *
 gtk_expander_accessible_get_keybinding (AtkAction *action,
                                         gint       i)
 {
-  GtkExpanderAccessible *expander;
   gchar *return_value = NULL;
   GtkWidget *widget;
   GtkWidget *label;
@@ -255,8 +254,6 @@ gtk_expander_accessible_get_keybinding (AtkAction *action,
   if (i != 0)
     return NULL;
 
-  expander = GTK_EXPANDER_ACCESSIBLE (action);
-
   label = gtk_expander_get_label_widget (GTK_EXPANDER (widget));
   if (GTK_IS_LABEL (label))
     {
diff --git a/gtk/a11y/gtkmenuitemaccessible.c b/gtk/a11y/gtkmenuitemaccessible.c
new file mode 100644 (file)
index 0000000..3f8d908
--- /dev/null
@@ -0,0 +1,605 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include <gtk/gtk.h>
+#include "gtkmenuitemaccessible.h"
+#include "gtksubmenuitemaccessible.h"
+
+#define KEYBINDING_SEPARATOR ";"
+
+static void menu_item_select   (GtkMenuItem *item);
+static void menu_item_deselect (GtkMenuItem *item);
+
+static GtkWidget *get_label_from_container   (GtkWidget *container);
+static gchar     *get_text_from_label_widget (GtkWidget *widget);
+
+
+static void atk_action_interface_init (AtkActionIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkMenuItemAccessible, gtk_menu_item_accessible, GAIL_TYPE_CONTAINER,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
+
+static void
+gtk_menu_item_accessible_initialize (AtkObject *obj,
+                                     gpointer   data)
+{
+  GtkWidget *widget;
+  GtkWidget *parent;
+
+  ATK_OBJECT_CLASS (gtk_menu_item_accessible_parent_class)->initialize (obj, data);
+
+  g_signal_connect (data, "select", G_CALLBACK (menu_item_select), NULL);
+  g_signal_connect (data, "deselect", G_CALLBACK (menu_item_deselect), NULL);
+
+  widget = GTK_WIDGET (data);
+  parent = gtk_widget_get_parent (widget);
+  if (GTK_IS_MENU (parent))
+    {
+      GtkWidget *parent_widget;
+
+      parent_widget =  gtk_menu_get_attach_widget (GTK_MENU (parent));
+
+      if (!GTK_IS_MENU_ITEM (parent_widget))
+        parent_widget = gtk_widget_get_parent (widget);
+      if (parent_widget)
+        atk_object_set_parent (obj, gtk_widget_get_accessible (parent_widget));
+    }
+
+  g_object_set_data (G_OBJECT (obj), "atk-component-layer", GINT_TO_POINTER (ATK_LAYER_POPUP));
+
+  if (GTK_IS_TEAROFF_MENU_ITEM (data))
+    obj->role = ATK_ROLE_TEAR_OFF_MENU_ITEM;
+  else if (GTK_IS_SEPARATOR_MENU_ITEM (data))
+    obj->role = ATK_ROLE_SEPARATOR;
+  else
+    obj->role = ATK_ROLE_MENU_ITEM;
+}
+
+static gint
+gtk_menu_item_accessible_get_n_children (AtkObject *obj)
+{
+  GtkWidget *widget;
+  GtkWidget *submenu;
+  gint count = 0;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return count;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  if (submenu)
+    {
+      GList *children;
+
+      children = gtk_container_get_children (GTK_CONTAINER (submenu));
+      count = g_list_length (children);
+      g_list_free (children);
+    }
+  return count;
+}
+
+static AtkObject *
+gtk_menu_item_accessible_ref_child (AtkObject *obj,
+                                    gint       i)
+{
+  AtkObject  *accessible;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  accessible = NULL;
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  if (submenu)
+    {
+      GList *children;
+      GList *tmp_list;
+
+      children = gtk_container_get_children (GTK_CONTAINER (submenu));
+      tmp_list = g_list_nth (children, i);
+      if (tmp_list)
+        {
+          accessible = gtk_widget_get_accessible (GTK_WIDGET (tmp_list->data));
+          g_object_ref (accessible);
+        }
+      g_list_free (children);
+    }
+
+  return accessible;
+}
+
+static AtkStateSet *
+gtk_menu_item_accessible_ref_state_set (AtkObject *obj)
+{
+  AtkObject *menu_item;
+  AtkStateSet *state_set, *parent_state_set;
+
+  state_set = ATK_OBJECT_CLASS (gtk_menu_item_accessible_parent_class)->ref_state_set (obj);
+
+  menu_item = atk_object_get_parent (obj);
+
+  if (menu_item)
+    {
+      if (!GTK_IS_MENU_ITEM (gtk_accessible_get_widget (GTK_ACCESSIBLE (menu_item))))
+        return state_set;
+
+      parent_state_set = atk_object_ref_state_set (menu_item);
+      if (!atk_state_set_contains_state (parent_state_set, ATK_STATE_SELECTED))
+        {
+          atk_state_set_remove_state (state_set, ATK_STATE_FOCUSED);
+          atk_state_set_remove_state (state_set, ATK_STATE_SHOWING);
+        }
+    }
+
+  return state_set;
+}
+
+static const gchar *
+gtk_menu_item_accessible_get_name (AtkObject *obj)
+{
+  const gchar *name;
+  GtkWidget *widget;
+  GtkWidget *label;
+  GtkMenuItemAccessible *accessible;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  name = ATK_OBJECT_CLASS (gtk_menu_item_accessible_parent_class)->get_name (obj);
+  if (name)
+    return name;
+
+  accessible = GTK_MENU_ITEM_ACCESSIBLE (obj);
+  label = get_label_from_container (widget);
+
+  g_free (accessible->text);
+  accessible->text = get_text_from_label_widget (label);
+
+  return accessible->text;
+}
+
+static void
+gtk_menu_item_accessible_finalize (GObject *object)
+{
+  GtkMenuItemAccessible *accessible = GTK_MENU_ITEM_ACCESSIBLE (object);
+
+  g_free (accessible->text);
+
+  G_OBJECT_CLASS (gtk_menu_item_accessible_parent_class)->finalize (object);
+}
+
+static void
+gtk_menu_item_accessible_notify_gtk (GObject    *obj,
+                                     GParamSpec *pspec)
+{
+  AtkObject* atk_obj;
+
+  atk_obj = gtk_widget_get_accessible (GTK_WIDGET (obj));
+
+  if (strcmp (pspec->name, "label") == 0)
+    {
+      if (atk_obj->name == NULL)
+        g_object_notify (G_OBJECT (atk_obj), "accessible-name");
+      g_signal_emit_by_name (atk_obj, "visible_data_changed");
+    }
+  else
+    GAIL_WIDGET_CLASS (gtk_menu_item_accessible_parent_class)->notify_gtk (obj, pspec);
+}
+
+static void
+gtk_menu_item_accessible_class_init (GtkMenuItemAccessibleClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+  GailWidgetClass *widget_class = (GailWidgetClass*)klass;
+
+  widget_class->notify_gtk = gtk_menu_item_accessible_notify_gtk;
+
+  gobject_class->finalize = gtk_menu_item_accessible_finalize;
+
+  class->get_n_children = gtk_menu_item_accessible_get_n_children;
+  class->ref_child = gtk_menu_item_accessible_ref_child;
+  class->ref_state_set = gtk_menu_item_accessible_ref_state_set;
+  class->initialize = gtk_menu_item_accessible_initialize;
+  class->get_name = gtk_menu_item_accessible_get_name;
+}
+
+static void
+gtk_menu_item_accessible_init (GtkMenuItemAccessible *menu_item)
+{
+}
+
+static GtkWidget *
+get_label_from_container (GtkWidget *container)
+{
+  GtkWidget *label;
+  GList *children, *tmp_list;
+
+  if (!GTK_IS_CONTAINER (container))
+    return NULL;
+
+  children = gtk_container_get_children (GTK_CONTAINER (container));
+  label = NULL;
+
+  for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next)
+    {
+      if (GTK_IS_LABEL (tmp_list->data))
+        {
+          label = tmp_list->data;
+          break;
+        }
+      else if (GTK_IS_CELL_VIEW (tmp_list->data))
+        {
+          label = tmp_list->data;
+          break;
+        }
+      else if (GTK_IS_BOX (tmp_list->data))
+        {
+          label = get_label_from_container (GTK_WIDGET (tmp_list->data));
+          if (label)
+            break;
+        }
+    }
+  g_list_free (children);
+
+  return label;
+}
+
+static gchar *
+get_text_from_label_widget (GtkWidget *label)
+{
+  if (GTK_IS_LABEL (label))
+    return g_strdup (gtk_label_get_text (GTK_LABEL (label)));
+  else if (GTK_IS_CELL_VIEW (label))
+    {
+      GList *cells, *l;
+      GtkTreeModel *model;
+      GtkTreeIter iter;
+      GtkTreePath *path;
+      GtkCellArea *area;
+      gchar *text;
+
+      model = gtk_cell_view_get_model (GTK_CELL_VIEW (label));
+      path = gtk_cell_view_get_displayed_row (GTK_CELL_VIEW (label));
+      gtk_tree_model_get_iter (model, &iter, path);
+      gtk_tree_path_free (path);
+
+      area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (label));
+      gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
+      cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (label));
+
+      text = NULL;
+      for (l = cells; l; l = l->next)
+        {
+          GtkCellRenderer *cell = l->data;
+
+          if (GTK_IS_CELL_RENDERER_TEXT (cell))
+            {
+              g_object_get (cell, "text", &text, NULL);
+              break;
+            }
+        }
+
+      g_list_free (cells);
+
+      return text;
+    }
+
+  return NULL;
+}
+
+static void
+ensure_menus_unposted (GtkMenuItemAccessible *menu_item)
+{
+  AtkObject *parent;
+  GtkWidget *widget;
+
+  parent = atk_object_get_parent (ATK_OBJECT (menu_item));
+  while (parent)
+    {
+      widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
+      if (GTK_IS_MENU (widget))
+        {
+          if (gtk_widget_get_mapped (widget))
+            gtk_menu_shell_cancel (GTK_MENU_SHELL (widget));
+
+          return;
+        }
+      parent = atk_object_get_parent (parent);
+    }
+}
+
+static gboolean
+gtk_menu_item_accessible_do_action (AtkAction *action,
+                                    gint       i)
+{
+  GtkWidget *item, *item_parent;
+  gboolean item_mapped;
+
+  item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
+  if (item == NULL)
+    return FALSE;
+
+  if (i != 0)
+    return FALSE;
+
+  if (!gtk_widget_get_sensitive (item) || !gtk_widget_get_visible (item))
+    return FALSE;
+
+  item_parent = gtk_widget_get_parent (item);
+  if (!GTK_IS_MENU_SHELL (item_parent))
+    return FALSE;
+
+  gtk_menu_shell_select_item (GTK_MENU_SHELL (item_parent), item);
+  item_mapped = gtk_widget_get_mapped (item);
+
+  /* This is what is called when <Return> is pressed for a menu item.
+   * The last argument means 'force hide'.
+   */
+  g_signal_emit_by_name (item_parent, "activate_current", 1);
+  if (!item_mapped)
+    ensure_menus_unposted (GTK_MENU_ITEM_ACCESSIBLE (action));
+
+  return TRUE;
+}
+
+static gint
+gtk_menu_item_accessible_get_n_actions (AtkAction *action)
+{
+  return 1;
+}
+
+static const gchar *
+gtk_menu_item_accessible_action_get_name (AtkAction *action,
+                                          gint       i)
+{
+  if (i != 0)
+    return NULL;
+
+  return "click";
+}
+
+static gboolean
+find_accel_by_widget (GtkAccelKey *key,
+                      GClosure    *closure,
+                      gpointer     data)
+{
+  /* We assume that closure->data points to the widget
+   * pending gtk_widget_get_accel_closures being made public
+   */
+  return data == (gpointer) closure->data;
+}
+
+static gboolean
+find_accel_by_closure (GtkAccelKey *key,
+                       GClosure    *closure,
+                       gpointer     data)
+{
+  return data == (gpointer) closure;
+}
+
+/* This function returns a string of the form A;B;C where A is
+ * the keybinding for the widget; B is the keybinding to traverse
+ * from the menubar and C is the accelerator. The items in the
+ * keybinding to traverse from the menubar are separated by ":".
+ */
+static const gchar *
+gtk_menu_item_accessible_get_keybinding (AtkAction *action,
+                                         gint       i)
+{
+  gchar *keybinding = NULL;
+  gchar *item_keybinding = NULL;
+  gchar *full_keybinding = NULL;
+  gchar *accelerator = NULL;
+  GtkWidget *item;
+  GtkWidget *temp_item;
+  GtkWidget *child;
+  GtkWidget *parent;
+
+  item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
+  if (item == NULL)
+    return NULL;
+
+  if (i != 0)
+    return NULL;
+
+  temp_item = item;
+  while (TRUE)
+    {
+      GdkModifierType mnemonic_modifier = 0;
+      guint key_val;
+      gchar *key, *temp_keybinding;
+
+      child = gtk_bin_get_child (GTK_BIN (temp_item));
+      if (child == NULL)
+        return NULL;
+
+      parent = gtk_widget_get_parent (temp_item);
+      if (!parent)
+        /* parent can be NULL when activating a window from the panel */
+        return NULL;
+
+      if (GTK_IS_MENU_BAR (parent))
+        {
+          GtkWidget *toplevel;
+
+          toplevel = gtk_widget_get_toplevel (parent);
+          if (toplevel && GTK_IS_WINDOW (toplevel))
+            mnemonic_modifier =
+              gtk_window_get_mnemonic_modifier (GTK_WINDOW (toplevel));
+        }
+
+      if (GTK_IS_LABEL (child))
+        {
+          key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
+          if (key_val != GDK_KEY_VoidSymbol)
+            {
+              key = gtk_accelerator_name (key_val, mnemonic_modifier);
+              if (full_keybinding)
+                temp_keybinding = g_strconcat (key, ":", full_keybinding, NULL);
+              else
+                temp_keybinding = g_strdup (key);
+
+              if (temp_item == item)
+                item_keybinding = g_strdup (key);
+
+              g_free (key);
+              g_free (full_keybinding);
+              full_keybinding = temp_keybinding;
+            }
+          else
+            {
+              /* No keybinding */
+              g_free (full_keybinding);
+              full_keybinding = NULL;
+              break;
+            }
+        }
+
+      /* We have reached the menu bar so we are finished */
+      if (GTK_IS_MENU_BAR (parent))
+        break;
+
+      g_return_val_if_fail (GTK_IS_MENU (parent), NULL);
+      temp_item = gtk_menu_get_attach_widget (GTK_MENU (parent));
+      if (!GTK_IS_MENU_ITEM (temp_item))
+        {
+          /* Menu is attached to something other than a menu item;
+           * probably an option menu
+           */
+          g_free (full_keybinding);
+          full_keybinding = NULL;
+          break;
+        }
+    }
+
+  parent = gtk_widget_get_parent (item);
+  if (GTK_IS_MENU (parent))
+    {
+      GtkAccelGroup *group;
+      GtkAccelKey *key;
+
+      group = gtk_menu_get_accel_group (GTK_MENU (parent));
+      if (group)
+        key = gtk_accel_group_find (group, find_accel_by_widget, item);
+      else
+        {
+          key = NULL;
+          child = gtk_bin_get_child (GTK_BIN (item));
+          if (GTK_IS_ACCEL_LABEL (child))
+            {
+              GtkAccelLabel *accel_label;
+              GClosure      *accel_closure;
+
+              accel_label = GTK_ACCEL_LABEL (child);
+              g_object_get (accel_label, "accel-closure", &accel_closure, NULL);
+              if (accel_closure)
+                {
+                  key = gtk_accel_group_find (gtk_accel_group_from_accel_closure (accel_closure),
+                                              find_accel_by_closure,
+                                              accel_closure);
+                  g_closure_unref (accel_closure);
+                }
+            }
+        }
+
+     if (key)
+       accelerator = gtk_accelerator_name (key->accel_key, key->accel_mods);
+   }
+
+  /* Concatenate the bindings */
+  if (item_keybinding || full_keybinding || accelerator)
+    {
+      gchar *temp;
+      if (item_keybinding)
+        {
+          keybinding = g_strconcat (item_keybinding, KEYBINDING_SEPARATOR, NULL);
+          g_free (item_keybinding);
+        }
+      else
+        keybinding = g_strdup (KEYBINDING_SEPARATOR);
+
+      if (full_keybinding)
+        {
+          temp = g_strconcat (keybinding, full_keybinding,
+                              KEYBINDING_SEPARATOR, NULL);
+          g_free (full_keybinding);
+        }
+      else
+        temp = g_strconcat (keybinding, KEYBINDING_SEPARATOR, NULL);
+
+      g_free (keybinding);
+      keybinding = temp;
+      if (accelerator)
+        {
+          temp = g_strconcat (keybinding, accelerator, NULL);
+          g_free (accelerator);
+          g_free (keybinding);
+          keybinding = temp;
+      }
+    }
+
+  return keybinding;
+}
+
+static void
+atk_action_interface_init (AtkActionIface *iface)
+{
+  iface->do_action = gtk_menu_item_accessible_do_action;
+  iface->get_n_actions = gtk_menu_item_accessible_get_n_actions;
+  iface->get_name = gtk_menu_item_accessible_action_get_name;
+  iface->get_keybinding = gtk_menu_item_accessible_get_keybinding;
+}
+
+static void
+menu_item_selection (GtkMenuItem  *item,
+                     gboolean      selected)
+{
+  AtkObject *obj, *parent;
+  gint i;
+
+  obj = gtk_widget_get_accessible (GTK_WIDGET (item));
+  atk_object_notify_state_change (obj, ATK_STATE_SELECTED, selected);
+
+  for (i = 0; i < atk_object_get_n_accessible_children (obj); i++)
+    {
+      AtkObject *child;
+      child = atk_object_ref_accessible_child (obj, i);
+      atk_object_notify_state_change (child, ATK_STATE_SHOWING, selected);
+      g_object_unref (child);
+    }
+  parent = atk_object_get_parent (obj);
+  g_signal_emit_by_name (parent, "selection_changed");
+}
+
+static void
+menu_item_select (GtkMenuItem *item)
+{
+  menu_item_selection (item, TRUE);
+}
+
+static void
+menu_item_deselect (GtkMenuItem *item)
+{
+  menu_item_selection (item, FALSE);
+}
diff --git a/gtk/a11y/gtkmenuitemaccessible.h b/gtk/a11y/gtkmenuitemaccessible.h
new file mode 100644 (file)
index 0000000..88470da
--- /dev/null
@@ -0,0 +1,53 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2001 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_MENU_ITEM_ACCESSIBLE_H__
+#define __GTK_MENU_ITEM_ACCESSIBLE_H__
+
+#include "gailcontainer.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_MENU_ITEM_ACCESSIBLE                     (gtk_menu_item_accessible_get_type ())
+#define GTK_MENU_ITEM_ACCESSIBLE(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU_ITEM_ACCESSIBLE, GtkMenuItemAccessible))
+#define GTK_MENU_ITEM_ACCESSIBLE_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MENU_ITEM_ACCESSIBLE, GtkMenuItemAccessibleClass))
+#define GTK_IS_MENU_ITEM_ACCESSIBLE(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MENU_ITEM_ACCESSIBLE))
+#define GTK_IS_MENU_ITEM_ACCESSIBLE_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MENU_ITEM_ACCESSIBLE))
+#define GTK_MENU_ITEM_ACCESSIBLE_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MENU_ITEM_ACCESSIBLE, GtkMenuItemAccessibleClass))
+
+typedef struct _GtkMenuItemAccessible      GtkMenuItemAccessible;
+typedef struct _GtkMenuItemAccessibleClass GtkMenuItemAccessibleClass;
+
+struct _GtkMenuItemAccessible
+{
+  GailContainer parent;
+
+  gchar *text;
+};
+
+struct _GtkMenuItemAccessibleClass
+{
+  GailContainerClass parent_class;
+};
+
+GType gtk_menu_item_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_MENU_ITEM_ACCESSIBLE_H__ */
diff --git a/gtk/a11y/gtksubmenuitemaccessible.c b/gtk/a11y/gtksubmenuitemaccessible.c
new file mode 100644 (file)
index 0000000..cf879eb
--- /dev/null
@@ -0,0 +1,298 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2002, 2003 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include "gtksubmenuitemaccessible.h"
+
+static gint menu_item_add_gtk    (GtkContainer   *container,
+                                  GtkWidget      *widget);
+static gint menu_item_remove_gtk (GtkContainer   *container,
+                                  GtkWidget      *widget);
+
+static void atk_selection_interface_init (AtkSelectionIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkSubmenuItemAccessible, gtk_submenu_item_accessible, GTK_TYPE_MENU_ITEM_ACCESSIBLE,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
+
+static void
+gtk_submenu_item_accessible_initialize (AtkObject *obj,
+                                        gpointer   data)
+{
+  GtkWidget *submenu;
+
+  ATK_OBJECT_CLASS (gtk_submenu_item_accessible_parent_class)->initialize (obj, data);
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (data));
+  g_return_if_fail (submenu);
+
+  g_signal_connect (submenu, "add", G_CALLBACK (menu_item_add_gtk), NULL);
+  g_signal_connect (submenu, "remove", G_CALLBACK (menu_item_remove_gtk), NULL);
+
+  obj->role = ATK_ROLE_MENU;
+}
+
+static void
+gtk_submenu_item_accessible_class_init (GtkSubmenuItemAccessibleClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->initialize = gtk_submenu_item_accessible_initialize;
+}
+
+static void
+gtk_submenu_item_accessible_init (GtkSubmenuItemAccessible *item)
+{
+}
+
+static gboolean
+gtk_submenu_item_accessible_add_selection (AtkSelection *selection,
+                                           gint          i)
+{
+  GtkMenuShell *shell;
+  GList *kids;
+  guint length;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+  GtkWidget *child;
+
+  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return FALSE;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
+  shell = GTK_MENU_SHELL (submenu);
+  kids = gtk_container_get_children (GTK_CONTAINER (shell));
+  length = g_list_length (kids);
+  if (i < 0 || i > length)
+    {
+      g_list_free (kids);
+      return FALSE;
+    }
+
+  child = g_list_nth_data (kids, i);
+  g_list_free (kids);
+  g_return_val_if_fail (GTK_IS_MENU_ITEM(child), FALSE);
+  gtk_menu_shell_select_item (shell, GTK_WIDGET (child));
+  return TRUE;
+}
+
+static gboolean
+gtk_submenu_item_accessible_clear_selection (AtkSelection *selection)
+{
+  GtkMenuShell *shell;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+
+  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return FALSE;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
+  shell = GTK_MENU_SHELL (submenu);
+
+  gtk_menu_shell_deselect (shell);
+  return TRUE;
+}
+
+static AtkObject *
+gtk_submenu_item_accessible_ref_selection (AtkSelection *selection,
+                                           gint          i)
+{
+  GtkMenuShell *shell;
+  AtkObject *obj;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+  GtkWidget *item;
+
+  if (i != 0)
+    return NULL;
+
+  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return NULL;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), NULL);
+  shell = GTK_MENU_SHELL (submenu);
+
+  item = gtk_menu_shell_get_selected_item (shell);
+  if (item != NULL)
+    {
+      obj = gtk_widget_get_accessible (item);
+      g_object_ref (obj);
+      return obj;
+    }
+
+  return NULL;
+}
+
+static gint
+gtk_submenu_item_accessible_get_selection_count (AtkSelection *selection)
+{
+  GtkMenuShell *shell;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+
+  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return 0;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), 0);
+  shell = GTK_MENU_SHELL (submenu);
+
+  if (gtk_menu_shell_get_selected_item (shell) != NULL)
+    return 1;
+
+  return 0;
+}
+
+static gboolean
+gtk_submenu_item_accessible_is_child_selected (AtkSelection *selection,
+                                               gint          i)
+{
+  GtkMenuShell *shell;
+  gint j;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+  GtkWidget *item;
+  GList *kids;
+
+  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return FALSE;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
+  shell = GTK_MENU_SHELL (submenu);
+
+  item = gtk_menu_shell_get_selected_item (shell);
+  if (item == NULL)
+    return FALSE;
+
+  kids = gtk_container_get_children (GTK_CONTAINER (shell));
+  j = g_list_index (kids, item);
+  g_list_free (kids);
+
+  return j==i;
+}
+
+static gboolean
+gtk_submenu_item_accessible_remove_selection (AtkSelection *selection,
+                                              gint          i)
+{
+  GtkMenuShell *shell;
+  GtkWidget *widget;
+  GtkWidget *submenu;
+  GtkWidget *item;
+
+  if (i != 0)
+    return FALSE;
+
+  widget =  gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
+  if (widget == NULL)
+    return FALSE;
+
+  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  g_return_val_if_fail (GTK_IS_MENU_SHELL (submenu), FALSE);
+  shell = GTK_MENU_SHELL (submenu);
+
+  item = gtk_menu_shell_get_selected_item (shell);
+  if (item && gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
+    gtk_menu_shell_deselect (shell);
+
+  return TRUE;
+}
+
+static void
+atk_selection_interface_init (AtkSelectionIface *iface)
+{
+  iface->add_selection = gtk_submenu_item_accessible_add_selection;
+  iface->clear_selection = gtk_submenu_item_accessible_clear_selection;
+  iface->ref_selection = gtk_submenu_item_accessible_ref_selection;
+  iface->get_selection_count = gtk_submenu_item_accessible_get_selection_count;
+  iface->is_child_selected = gtk_submenu_item_accessible_is_child_selected;
+  iface->remove_selection = gtk_submenu_item_accessible_remove_selection;
+}
+
+static gint
+menu_item_add_gtk (GtkContainer *container,
+                   GtkWidget    *widget)
+{
+  GtkWidget *parent_widget;
+  AtkObject *atk_parent;
+  AtkObject *atk_child;
+  GailContainer *gail_container;
+  gint index;
+
+  g_return_val_if_fail (GTK_IS_MENU (container), 1);
+
+  parent_widget = gtk_menu_get_attach_widget (GTK_MENU (container));
+  if (GTK_IS_MENU_ITEM (parent_widget))
+    {
+      atk_parent = gtk_widget_get_accessible (parent_widget);
+      atk_child = gtk_widget_get_accessible (widget);
+
+      g_object_notify (G_OBJECT (atk_child), "accessible-parent");
+      gail_container = GAIL_CONTAINER (atk_parent);
+      g_list_free (gail_container->children);
+      gail_container->children = gtk_container_get_children (container);
+      index = g_list_index (gail_container->children, widget);
+      g_signal_emit_by_name (atk_parent, "children_changed::add",
+                             index, atk_child, NULL);
+    }
+  return 1;
+}
+
+static gint
+menu_item_remove_gtk (GtkContainer *container,
+                      GtkWidget    *widget)
+{
+  GtkWidget *parent_widget;
+  AtkObject *atk_parent;
+  AtkObject *atk_child;
+  GailContainer *gail_container;
+  gint index;
+  gint list_length;
+
+  g_return_val_if_fail (GTK_IS_MENU (container), 1);
+
+  parent_widget = gtk_menu_get_attach_widget (GTK_MENU (container));
+  if (GTK_IS_MENU_ITEM (parent_widget))
+    {
+      atk_parent = gtk_widget_get_accessible (parent_widget);
+      atk_child = gtk_widget_get_accessible (widget);
+
+      g_object_notify (G_OBJECT (atk_child), "accessible-parent");
+
+      gail_container = GAIL_CONTAINER (atk_parent);
+      index = g_list_index (gail_container->children, widget);
+      list_length = g_list_length (gail_container->children);
+      g_list_free (gail_container->children);
+      gail_container->children = gtk_container_get_children (container);
+      if (index >= 0 && index <= list_length)
+        g_signal_emit_by_name (atk_parent, "children_changed::remove",
+                               index, atk_child, NULL);
+    }
+  return 1;
+}
diff --git a/gtk/a11y/gtksubmenuitemaccessible.h b/gtk/a11y/gtksubmenuitemaccessible.h
new file mode 100644 (file)
index 0000000..4f7fbba
--- /dev/null
@@ -0,0 +1,51 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2002 Sun Microsystems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_SUBMENU_ITEM_ACCESSIBLE_H__
+#define __GTK_SUBMENU_ITEM_ACCESSIBLE_H__
+
+#include "gtkmenuitemaccessible.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE                     (gtk_submenu_item_accessible_get_type ())
+#define GTK_SUBMENU_ITEM_ACCESSIBLE(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE, GtkSubmenuItemAccessible))
+#define GTK_SUBMENU_ITEM_ACCESSIBLE_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE, GtkSubmenuItemAccessibleClass))
+#define GTK_IS_SUBMENU_ITEM_ACCESSIBLE(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE))
+#define GTK_IS_SUBMENU_ITEM_ACCESSIBLE_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE))
+#define GTK_SUBMENU_ITEM_ACCESSIBLE_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE, GtkSubmenuItemAccessibleClass))
+
+typedef struct _GtkSubmenuItemAccessible      GtkSubmenuItemAccessible;
+typedef struct _GtkSubmenuItemAccessibleClass GtkSubmenuItemAccessibleClass;
+
+struct _GtkSubmenuItemAccessible
+{
+  GtkMenuItemAccessible parent;
+};
+
+struct _GtkSubmenuItemAccessibleClass
+{
+  GtkMenuItemAccessibleClass parent_class;
+};
+
+GType gtk_submenu_item_accessible_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GTK_SUBMENU_ITEM_ACCESSIBLE_H__ */
index 32d35e480ab7d15359ca854e962c16c20d4bf534..3bb0da8c64130fe31a3d34c7a243ad8535ca7b48 100644 (file)
@@ -43,6 +43,8 @@
 #include "gtkwidgetprivate.h"
 #include "gtkintl.h"
 #include "gtktypebuiltins.h"
+#include "a11y/gtkmenuitemaccessible.h"
+#include "a11y/gtksubmenuitemaccessible.h"
 
 
 /**
@@ -207,6 +209,23 @@ G_DEFINE_TYPE_WITH_CODE (GtkMenuItem, gtk_menu_item, GTK_TYPE_BIN,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
                                                 gtk_menu_item_activatable_interface_init))
 
+static AtkObject *
+gtk_menu_item_get_accessible (GtkWidget *widget)
+{
+  GObject *object;
+  AtkObject *accessible;
+
+  /* FIXME this is not really right, submenus can come and go */
+  if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)))
+    object = g_object_new (GTK_TYPE_SUBMENU_ITEM_ACCESSIBLE, NULL);
+  else
+    object = g_object_new (GTK_TYPE_MENU_ITEM_ACCESSIBLE, NULL);
+
+  accessible = ATK_OBJECT (object);
+  atk_object_initialize (accessible, widget);
+
+  return accessible;
+}
 
 static void
 gtk_menu_item_class_init (GtkMenuItemClass *klass)
@@ -235,6 +254,7 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass)
   widget_class->get_preferred_width = gtk_menu_item_get_preferred_width;
   widget_class->get_preferred_height = gtk_menu_item_get_preferred_height;
   widget_class->get_preferred_height_for_width = gtk_menu_item_get_preferred_height_for_width;
+  widget_class->get_accessible = gtk_menu_item_get_accessible;
 
   container_class->forall = gtk_menu_item_forall;